#!/bin/bash
#备份php工程

#工程目录路径 工程名 备份文件路径
#./beetle_php_bak.sh tom /usr/local winit_tom /home/beetle/shell/tom-20161124100406.tgz
#./beetle_php_bak.sh eds /usr/local winit_eds /home/beetle/shell/eds-20161124100406.tgz


function bak_tom(){
    cd $1 && tar -zcf $3 $2 --exclude=$2/Logs --exclude=$2/Logs.bak --exclude=$2/Uploads --exclude=$2/who --exclude=$2/winitho
    cd $2 && sudo rm -rf Apps/Runtime/*
}
function bak_eds(){
    cd $1 && tar -zcf $3 $2 --exclude=$2/Logs
    cd $2 && sudo rm -rf Apps/Runtime/*
}
function bak_sellerportal(){
    cd $1 && tar -zcf $3 $2 --exclude=$2/Upload --exclude=$2/Public/Uploads --exclude=$2/DataCache --exclude=$2/RuntimeLogs --exclude=$2/cache --exclude=$2/images --exclude=$2/logs --exclude=$2/templates --exclude=$2/winitconf --exclude=$2/media/k2 --exclude=$2/invoice --exclude=$2/en
    cd $2 && sudo rm -rf ThinkPHP bom.php Manage/Runtime/* Finance Agent Admin
}
function bak_help(){
    cd $1 && tar -zcf $3 $2 --exclude=$2/Logs
    cd $2 && sudo rm -rf Apps/Runtime/*
}
function bak_jinxuan(){
    cd $1 && tar -zcf $3 $2
    cd $2 && sudo rm -rf Apps/Runtime/*
}
function bak_booking(){
    cd $1 && tar -zcf $3 $2
    cd $2 && sudo rm -rf Agent/Runtime/*
}
function bak_tracking(){
    cd $1 && tar -zcf $3 $2 --exclude=$2/tracking/Runtime --exclude=$2/RuntimeLogs
    cd $2 && sudo rm -rf tracking/Runtime/*
}

function bak_apiwebsite(){
    cd $1 && tar -zcf $3 $2 --exclude=$2/Index/Runtime
}

function bak_crm(){
    cd $1 && tar -zcf $3 $2 --exclude=$2/logs --exclude=$2/cache
    cd $2 && sudo rm -rf layouts/* modules/*
}

function bak_wanyilian(){
    cd $1 && tar -zcf $3 $2 --exclude=$2/chongzhi/log --exclude=$2/chongzhi/uploads --exclude=$2/erp/log --exclude=$2/erp/uploads --exclude=$2/kefu/log --exclude=$2/kefu/uploads
}

function bak(){
    cd $1 && tar -zcf $3 $2
}

case "$1" in
	tom )
		bak_tom $2 $3 $4;;
    eds )
		bak_eds $2 $3 $4;;
    sellerportal )
		bak_sellerportal $2 $3 $4;;
    help )
		bak_help $2 $3 $4;;
    jinxuan )
		bak_jinxuan $2 $3 $4;;
	booking )
		bak_booking $2 $3 $4;;
	tracking )
		bak_tracking $2 $3 $4;;
	apiwebsite )
		bak_apiwebsite $2 $3 $4;;
	crm )
		bak_crm $2 $3 $4;;
	wanyilian )
    	bak_wanyilian $2 $3 $4;;
    default )
		bak $2 $3 $4;;
	*)
		echo "[ERROR]参数错误:$1"
esac
exit 0
